﻿from airtest.core.api import *
from airtest.cli.parser import cli_setup
from airtest.aircv import *

if not cli_setup():
    auto_setup(__file__, logdir=True, devices=[
        "Android:///",
    ])

# script content
# print("start...")

# touch(Template(r"tpl1608705365124.png", record_pos=(0.443, -0.893), resolution=(1080, 2340)))
# sleep(1.0)

# touch(Template(r"tpl1608705372955.png", record_pos=(-0.011, 0.214), resolution=(1080, 2340)))
# sleep(59.0)
# if exists(Template(r"tpl1608706256857.png", record_pos=(0.398, -0.894), resolution=(1080, 2340))):
#    touch(Template(r"tpl1608706266784.png", record_pos=(0.393, -0.893), resolution=(1080, 2340)))
#    sleep(1.0)

# elif exists(Template(r"tpl1608706287434.png", record_pos=(-0.201, 1.024), resolution=(1080, 2340))):
#    touch(Template(r"tpl1608706300263.png", record_pos=(-0.206, 1.025), resolution=(1080, 2340)))
# else:
#    print("没找到。。。")

from PIL import Image
import pytesseract

print("start")
# 局部截图
screen = G.DEVICE.snapshot()

local = aircv.crop_image(screen, (0.719, 0.079, 0.756, 0.106))

# 保存局部截图到指定文件中
pil_image = cv2_2_pil(local)
pil_image.save("/Users/gzyhp/Desktop/987654/hp.png", quality=99, optimize=True)

# 读取截图并识别截图中的文字
image = Image.open("/Users/gzyhp/Desktop/987654/hp.png")
text = pytesseract.image_to_string(image)
print("--------------初始数据为-----------------")
print(text)

# generate html report
# from airtest.report.report import simple_report
# simple_report(__file__, logpath=True)